package com.mhf.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.mhf.domain.User;
import com.mhf.feign.UserService;
import com.mhf.sentinel.OrderFallbackClass;
import com.mhf.sentinel.OrderblockHandlerClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private UserService userService;
    @RequestMapping("/getById/{id}")
    @SentinelResource(value="order-server-getById",
            blockHandler = "getByIdBlockHandler",
            blockHandlerClass = OrderblockHandlerClass.class,
            fallback = "getByIdFallback",
            fallbackClass = OrderFallbackClass.class)
    public User getById(@PathVariable("id") Long id){

        int i= 1/0;
        return userService.getById(id);
    }
    /*public User getByIdBlockHandler(@PathVariable("id") Long id, BlockException e){
        e.printStackTrace();
        return new User(-1L, "服务降级触发！", "当前服务流量过大，请稍后重试！");
    }*/
}
